package com.sias.controller;

import com.sias.common.result.Result;
import com.sias.common.result.ResultCodeEnum;
import com.sias.entity.dto.LoginDto;
import com.sias.entity.pojo.User;
import com.sias.entity.vo.LoginVo;
import com.sias.entity.vo.ValidateCodeVo;
import com.sias.service.UserService;
import com.sias.service.ValidateCodeService;
import com.sias.utils.AuthContextUtil;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/index")
public class IndexController {

    @Autowired
    private ValidateCodeService validateCodeService;

    @Autowired
    private UserService userService;

    @Operation(description = "用户登录")
    @RequestMapping(value = "/login")
    public Result login(@RequestBody LoginDto loginDto) {
        LoginVo loginVo=userService.login(loginDto);
        return Result.build(loginVo, ResultCodeEnum.SUCCESS);
    }

    @Operation(description = "验证码获取")
    @GetMapping(value = "/generateValidateCode")
    public Result<ValidateCodeVo> generateValidateCode() {
        ValidateCodeVo validateCodeVo = validateCodeService.generateValidateCode();
        return Result.build(validateCodeVo , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/getUserInfo")
    public Result<User> getUserInfo() {

        return Result.build(AuthContextUtil.get() , ResultCodeEnum.SUCCESS) ;
    }


//    @Operation(description = "用户注册")
//    @RequestMapping(value = "/redister")
//    public Result register(@RequestBody RegisterVo registerVo) {
//        userService.register(registerVo);
//        return Result.build(null,200,"注册成功");
//    }


}
